package com.aranandroid.customview.edit

import android.content.Context
import android.widget.LinearLayout
import com.aranandroid.customview.squareview.SquareEdit
import android.text.TextWatcher
import android.text.Editable
import android.text.TextUtils
import android.util.AttributeSet
import android.view.LayoutInflater
import com.aranandroid.customview.R
import androidx.appcompat.widget.AppCompatEditText

/**
 * 保证光标始终在最后面
 */
class LastInputEditText : AppCompatEditText {
    constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
        context!!, attrs, defStyle
    ) {
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(
        context!!, attrs
    ) {
    }

    constructor(context: Context?) : super(context!!) {}

    override fun onSelectionChanged(selStart: Int, selEnd: Int) {
        super.onSelectionChanged(selStart, selEnd)
        //保证光标始终在最后面
        if (selStart == selEnd) { //防止不能多选
            setSelection(text!!.length)
        }
    }
}